package com.sudo.boot.mapper.sys.entity;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import com.mybatisflex.core.handler.Fastjson2TypeHandler;
import com.sudo.boot.base.util.BootBeanMapUtil;
import com.sudo.boot.mybatisflex.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统配置
 *
 * @author DayDayUp
 * @datetime 2023-11-15 12:03
 **/
@Data
@Table(value = "sys_config")
@EqualsAndHashCode(callSuper = true)
public class SysConfig extends BaseEntity {
    /**
     * 乐观锁
     */
    @Id(keyType = KeyType.Auto)
    private Integer id;

    private String key;

    @Column(typeHandler = Fastjson2TypeHandler.class)
    private Map<String,Object> config;

    public void addConfig(Object obj){
        this.config = BootBeanMapUtil.beanToMap(obj);
    }

    public void addConfig(String key,Object obj){
        if (this.config == null){
            this.config = new HashMap<>();
        }
        this.config.put(key, obj);
    }

    public void delConfig(String key){
        if (this.config == null){
            this.config = new HashMap<>();
        }
        this.config.remove(key);
    }

}
